package com.tangsm.api.demo.controller;

import com.tangsm.api.demo.annotation.ResponseResultBody;
import com.tangsm.api.demo.result.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Result API 封装测试
 * @author 湯神码
 * @date 2020/10/20
 */
@RestController
@RequestMapping("/result")
@ResponseResultBody
public class HelloResultController {

    private static final HashMap<String, Object> INFO;

    static {
        INFO = new HashMap<>();
        INFO.put("name", "galaxy");
        INFO.put("age", "70");
    }

    /**
     * API 注解统一返回
     * @return Map
     */
    @GetMapping("hello")
    public Map<String, Object> hello() {
        return INFO;
    }

    /**
     * 测试重复包裹
     * @return Result<Map<String, Object>>
     */
    @GetMapping("result")
    public Result<Map<String, Object>> helloResult() {
        return Result.success(INFO);
    }
}